﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.Threading;
using FCMS.Entities;

namespace FCMS.Mvc.Security.Principal
{
    public class UserIdentity : IIdentity
    {
        public static UserIdentity Current
        {
            get
            {
                return (Thread.CurrentPrincipal.Identity) as UserIdentity;
            }
        }

        private static UserIdentity s_anonymous = new UserIdentity
        {
            UserID = -1,
            Name = "",
            IsActivated = false,
            IsAnonymous = true,
        };

        public static UserIdentity Anonymous
        {
            get
            {
                return s_anonymous;
            }
        }

        public UserIdentity() { }

        public UserIdentity(User user)
        {
            this.UserID = user.UserID;
            this.Name = user.UserName;
            //this.IsActivated = user.Activated;
            this.IsAnonymous = false;
        }

        public int UserID { get; private set; }

        public string Name { get; private set; }

        public bool IsActivated { get; private set; }

        public bool IsAnonymous { get; private set; }




        #region IIdentity Members

        string IIdentity.AuthenticationType
        {
            get
            {
                return "Detective";
            }
        }

        bool IIdentity.IsAuthenticated
        {
            get
            {
                return !this.IsAnonymous;
            }
        }

        string IIdentity.Name
        {
            get
            {
                return this.Name;
            }
        }

        #endregion

    }
}
